home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / tcombo.exe / TSINPUTL.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1992-11-18  |  4.3 KB  |  159 lines

  1. /*************************************************************************/
  2. /*                                                                       */
  3. /* TSINPUTL.H                                                            */
  4. /*                                                                       */
  5. /* Copyright (c) 1992, Vincent J. Dentice                                */
  6. /* All rights reserved                                                   */
  7. /*                                                                       */
  8. /*                                                                       */
  9. /*   Date    Prg  Ver  Description                                       */
  10. /* --------  ---  ---  ------------------------------------------------- */
  11. /* 09/30/92  VJD  0.1  Initial module definition.                        */
  12. /* 11/16/92  VJD  0.2  Added streamability to TStaticInputLine class.    */
  13. /* 11/17/92  VJD  0.3  Replaced matchFirstChar() function with member    */
  14. /*                     function getNextMatch().                          */
  15. /* 11/17/92  RG   0.3  Added functionality to jump to the beginning and  */
  16. /*                     end of the list by using the HOME and END keys.   */
  17. /*                     This code was supplied by Robert Gloeckner        */
  18. /*                     (100034,3033).                                    */
  19. /*                                                                       */
  20. /*************************************************************************/
  21.  
  22. #include <ctype.h>
  23. #include <string.h>
  24.  
  25. #define Uses_TEvent
  26. #define Uses_TKeys
  27. #define Uses_TStaticInputLine
  28. #define Uses_TStreamableClass
  29. #include "tsinputl.h"
  30.  
  31. Boolean matchFirstChar(void *, void *);
  32.  
  33.  
  34. TStaticInputLine::TStaticInputLine(const TRect& bounds, int aMaxLen, TCollection *aList) :
  35.           TInputLine(bounds, aMaxLen)
  36. {
  37.    list = aList;
  38. }
  39.  
  40.  
  41. void *TStaticInputLine::getNextMatch(char testChar)
  42. {
  43.    return (char *)list->firstThat(matchFirstChar, &testChar);
  44. }
  45.  
  46.  
  47. void TStaticInputLine::handleEvent(TEvent& event)
  48. {
  49.    char key, testChar[2];
  50.    char *tempData;
  51.    ccIndex index;
  52.  
  53.    if (event.what == evKeyDown) {
  54.       if (isprint(event.keyDown.charScan.charCode)) {
  55.      testChar[0] = event.keyDown.charScan.charCode;
  56.      testChar[1] = '\0';
  57.      tempData = (char *)getNextMatch(testChar[0]);
  58.      if (tempData != 0) {
  59.         strcpy(data, tempData);
  60.         selectAll(True);
  61.         drawView();
  62.      }
  63.      clearEvent(event);
  64.       }
  65.       else
  66.      switch (event.keyDown.keyCode) {
  67.         case kbUp :
  68.            index = list->indexOf(data) - 1;
  69.            if (index < 0)
  70.           index = list->getCount() - 1;
  71.            strcpy(data, (char *)list->at(index));
  72.            selectAll(True);
  73.            drawView();
  74.            clearEvent(event);
  75.            break;
  76.  
  77.         case kbDown :
  78.            index = list->indexOf(data) + 1;
  79.            if (index >= list->getCount())
  80.           index = 0;
  81.            strcpy(data, (char *)list->at(index));
  82.            selectAll(True);
  83.            drawView();
  84.            clearEvent(event);
  85.            break;
  86.  
  87.         case kbHome:
  88.            index = 0;
  89.            strcpy(data, (char *)list->at(index));
  90.            selectAll(True);
  91.            drawView();
  92.            clearEvent(event);
  93.            break;
  94.  
  95.         case kbEnd:
  96.            index = list->getCount() - 1;
  97.            strcpy(data, (char *)list->at(index));
  98.            selectAll(True);
  99.            drawView();
  100.            clearEvent(event);
  101.            break;
  102.  
  103.         case kbLeft  :
  104.         case kbRight :
  105.         case kbBack  :
  106.         case kbIns   :
  107.         case kbDel   : clearEvent(event);
  108.      }
  109.    }
  110.    TInputLine::handleEvent(event);
  111. }
  112.  
  113.  
  114. void TStaticInputLine::newList(TCollection *aList)
  115. {
  116.    if (list)
  117.       destroy(list);
  118.    list = aList;
  119.    drawView();
  120. }
  121.  
  122.  
  123. void *TStaticInputLine::read( ipstream& is )
  124. {
  125.    TInputLine::read(is);
  126.    is >> list;
  127.    return this;
  128. }
  129.  
  130.  
  131. void TStaticInputLine::write( opstream& os )
  132. {
  133.    TInputLine::write(os);
  134.    os << list;
  135. }
  136.  
  137. TStreamable *TStaticInputLine::build()
  138. {
  139.    return new TStaticInputLine(streamableInit);
  140. }
  141.  
  142.  
  143. TStaticInputLine::TStaticInputLine(StreamableInit) : TInputLine(streamableInit) { }
  144.  
  145.  
  146.  
  147. Boolean matchFirstChar(void *string1, void *string2)
  148. {
  149.    char *temp1, *temp2;
  150.  
  151.    temp1 = (char *)string1;
  152.    temp2 = (char *)string2;
  153.  
  154.    if (toupper(temp1[0]) == toupper(temp2[0]))
  155.       return True;
  156.    else
  157.       return False;
  158. }
  159.